package solutions.contest.week272;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/contest/weekly-contest-272/problems/find-first-palindromic-string-in-the-array/">2108.找出数组中的第一个回文字符串</a>
 */
public class Solution2108 extends BaseSolution {

    private boolean isPali(String str) {
        int p1 = 0, p2 = str.length() - 1;
        while(p1 < p2) {
            if(str.charAt(p1++) != str.charAt(p2--)) {
                return false;
            }
        }
        return true;
    }

    public String firstPalindrome(String[] words) {
        for(String str : words) {
            if (isPali(str)) {
                return str;
            }
        }
        return "";
    }

    public static void main(String[] args) {
        Solution2108 solution = new Solution2108();
        String str = solution.firstPalindrome(new String[]
                        {"abc","car","ada","racecar","cool"}
                );
        System.out.println(str);
    }
}